package com.neuedu.his.dao;

import com.neuedu.his.entity.ConstantItem;
import com.neuedu.his.entity.ConstantType;
import com.neuedu.his.framework.BaseDao;
import com.neuedu.util.JDBCUtil;

import java.util.List;

/**
 * 项目：      his
 * 类名:       ConstantTypeDao
 * 创建时间：  2020/12/23  8:43
 * 描述 :     用户数据访问层
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
public class ConstantItemDao implements BaseDao<ConstantItem> {


    public List<ConstantItem> selectList(String sql, Object... args) {
        return JDBCUtil.executeQuery(sql, ConstantItem.class, args);
    }



    @Override
    public ConstantItem selectById(Integer id) {
        String sql = " select * from constant_item where id = ?";
        return JDBCUtil.getOne(sql, ConstantItem.class, id);
    }

    @Override
    public boolean update(ConstantItem constantItem) {

        String sql = " UPDATE  constant_item SET  type_id = ?,  code = ?,  name = ?,  sort = ? WHERE id = ? ";

        return JDBCUtil.executeUpdate(sql,
                constantItem.getTypeId(),
                constantItem.getCode(),
                constantItem.getName(),
                constantItem.getSort(),
                constantItem.getId()
        );
    }


    /**
     * 逻辑删除，没有真正删除数据
     *
     * @param id
     * @return
     */
    @Override
    public boolean deleteById(Integer id) {

        String sql = " update  constant_item set active = 0 where id  = ? ";

        return JDBCUtil.executeUpdate(sql, id);
    }

    @Override
    public boolean batchDel(String sql, Object... parm) {
        return false;
    }

    @Override
    public boolean insert(ConstantItem item) {
        String sql = " INSERT INTO constant_item(  type_id ,  code ,  name ,  sort)   VALUES ( ? , ?,? , ?)  ";
        return JDBCUtil.executeUpdate(sql,   item.getTypeId(),
                item.getCode(),
                item.getName(),
                item.getSort());
    }


}
